package ReCallADSL;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.Util.GeneralThreadPool;

public class CheckADSL implements Runnable {

	private static final Logger _log = Logger.getLogger(CheckADSL.class.getName());
	private static boolean _inerror;


	private void runBat(){
		try{
			Process p=Runtime.getRuntime().exec("recallADSL.bat"); //執行DOS指令settime.bat
			p.waitFor();
			p.destroy(); //破壞物件
			Thread.sleep(1000);
			System.out.println("重新連線刷新完成。");
			_inerror = false;
		}catch(Exception e){
			_log.log(Level.SEVERE, e.getLocalizedMessage(),e);
		}
	}

	@Override
	public void run() {
		
		while(true){
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			if(_inerror){
				return;
			}
			try {
				InetAddress.getByName("www.google.com.tw");//www.google.com.tw
			} catch (UnknownHostException e) {
				GeneralThreadPool.getInstance().execute(new SendADSL());
				runBat();
			}
		}
	}


}